import React, {Component} from "react";
import {NavBar,Icon,WhiteSpace,WingBlank,List,TextareaItem,ImagePicker,Button} from 'antd-mobile'
import { createForm } from 'rc-form';
import axios from "axios"
import "./subPages.css"

const data = [];
class PublishBlog extends React.Component{
    constructor(props) {
        super(props);
    }
    Blog(){
        var blog=this.props.form.getFieldValue('blog');
        if(blog===undefined||blog===""){
            alert("动态内容不能为空！");
            return;
        }
        var getPhoneNum=document.cookie.split('=')[1]
        axios.get(global.routes.database+'/setBlogs',{
            params:{
                phoneNum:getPhoneNum,
                words:blog,
                imgs:'',
                type:1
            }
        }).then((res)=>{
            if(res.data.Code==1){
                alert("博客上传成功");
                window.location.href = '#/terran/publish';
            }
        })
    }
    state = {
        files: data,
    };
    onChange = (files, type, index) => {
        console.log(files, type, index);
        this.setState({
            files,
        });
    };

    onTabChange = (key) => {
        console.log(key);
    };
    render() {
        const { files } = this.state;
        const { getFieldProps } = this.props.form;
        return (
            <div>
                <NavBar
                    className="publish-subPages-NavBar"
                    mode="light"
                    icon={<Icon type="left" />}
                    onLeftClick={() => {
                        window.location.href = '#/terran/publish'
                    }}
                    rightContent={[
                        <Icon key="0" type="search" style={{ marginRight: '16px' }} />,
                        <Icon key="1" type="ellipsis" />,
                    ]}
                >发布动态</NavBar>
                <WhiteSpace />
                <List>
                    <TextareaItem
                        {...getFieldProps('blog')}
                        rows={5}
                        count={100}
                        placeholder="分享你此刻的想法"
                    />
                </List>
                <WingBlank>
                    <ImagePicker
                        files={files}
                        onChange={this.onChange}
                        onImageClick={(index, fs) => console.log(index, fs)}
                        selectable={files.length < 7}
                        multiple={true}
                    />
                </WingBlank>
                <WhiteSpace />
                <WhiteSpace />
                <WhiteSpace />
                <WingBlank style={{position:"relative"}}>
                    <Button type="primary" onClick={this.Blog.bind(this)}>发布</Button>
                </WingBlank>
            </div>
        );
    }
}
const PublishBlogWrapper = createForm()(PublishBlog);
export default PublishBlogWrapper;
